/* - Index - */
$(document).on("pageInit","#Pagelogin",function(e, pageId, $page) {

        if (is_weixin()) {

            $("#wxLoginDiv").show();
        }
    var loginShowMsg = undefined;
    try {
    loginShowMsg =  JSON.parse(window.localStorage.getItem("loginShowMsg"));
    }catch (e){}
    if(loginShowMsg){
        try {
        $(".login-header").html(buildLoginH(loginShowMsg));

        }catch (e){}
    }


    function buildLoginH(data) {

        var html='';
        try {
        html+='<div class="login-show">';
        html+='<img src="' + data["headImage"] + '" />';
        html+=' <h5>' + data["nickName"] + '</h5>';
        html+='</div>';
        html+='';
        }catch (e){}
        return html;
    }


    var isClick = true;

    $(".verify").on("click",function () {

        if(!isClick){
            return false;
        }
        var obj = {
             body:{
                phone:$("#mobile").val()
             }
         };

         var self = $(this);
         var seconds = 60;
         if(validatemobile(obj.body.phone)){
             isClick = false;
             var setSencend = setInterval(function(e){
                 seconds--;
                 self.text( seconds + "s重新发送" );
                 if( seconds < 1){
                     isClick = true;
                     self.text( "发送验证码" );
                     clearInterval(setSencend);
                 }
             },1000);

             getVerifyCodes(obj);


         }else{
         $.toast("手机号码不能为空");
         }


    });


    $("#loginbtn").on("click",function () {
        var obj = {
            body:{
                userPhoneNumber: $("#mobile").val(),
                code:$("#password").val()
            }
        };
        if(validatemobile(obj.body.userPhoneNumber) && obj.body.code !=="" ){
         login(obj,function(data){

         if(data.head.code === 1){

         $.toast("登录成功!");
         arbanbanLoad("/api/store/page/index");

         }else{
         $.toast(data.head.message);
         }

         });
         }else{

         if( !validatemobile(obj.body.userPhoneNumber) ){
         $.toast( "手机号码格式不正确，请重新填写" );
         }else
         if( obj.body.code === "" ){
         $.toast( "验证码不能为空" );
         }

         }
    });

    $("#wxLoginbtn").on("click",function () {
        window.location="/api/store/login/wx";
    });

});


// 首页
$(document).on("pageInit","#pageIndex" ,function(e, pageId, $page) {
    window.localStorage.clear();
    wx.ready(function(){
        console.log("商品页面准备完成----------------------------");
        setWxEvent();
    });
     if( window.location.pathname=="/api/store/page/index"){
         $(".index-ad").hide();
    }else{
         $(".index-ad").show();
    }
    $(".index-close").on("click",function (e) {
        $(".index-ad").hide();
    })
     $("#d").show();

    $(".index-ad-href").on("click",function (e) {
        var goodsId = $(this).attr("goodsId");
        window.localStorage.setItem("goodsId",goodsId);
        arbanbanLoad('/api/store/page/goods/detail/'+goodsId);
    })


    var banner  = {
        head : {
            crossDomain : 'crossDomain_banner'
        },
        body : {}
    };
    var list  = {
        head : {
            crossDomain : 'crossDomain_list',
            client:"Web"
        },
        body : {}
    };
    bannerList(banner,function (data) {
        $(".index-banner").html(buildBanner(data));
        var swiper = new Swiper('.swiper-container', {
            direction: 'horizontal',
            loop: true,
            autoplay : 2500,
            pagination: '.swiper-pagination'
        })
    })

    var p = {
        body : {
            pageNumber : 1,
            pageSize:99
        }
    };
    getGoodsList(p,function(data){

        // $(".goods-list").html(buildList(data.body));
        $(".goods-list").html(buildTotalGoodsList(data.body))

        $(".totalgoods-item").on('click',function (e) {
            var goodsId = $(this).attr("goodsId");

            window.localStorage.setItem("goodsId",goodsId);
            arbanbanLoad('/api/store/page/goods/detail/'+goodsId);
        } )




    })

    getHotGoodsList(p,function (data) {

        $(".hotGoods-list").html(buildTasteGoodsList(data.body));
        $(".goods-item").on('click',function (e) {
            var goodsId = $(this).attr("goodsId");
            window.localStorage.setItem("goodsId",goodsId);
            // $.toast(window.localStorage.getItem("goodsId"));
            arbanbanLoad('/api/store/page/goods/taste/detail/'+goodsId);
        } )
    })



   /*
   *



    <!-- 如果需要分页器 -->


   *
   * */

    function buildBanner(data){
        var html ='';

        html+='<div class="swiper-container">';
        html+='<div class="swiper-wrapper banner-list">';

        for(var i = 0;i < data.body.length;i++){
            var url="/";
            var target = data.body[i]["target"];
            if( data.body[i]["targetType"]==1){
                url =getHost()+"/api/store/page/goods/detail/"+target;
            }
            html+='<div class="swiper-slide">';
            html+='<img onclick="arbanbanLoad(\''+url+'\')" src=" ' + data.body[i]["bannerImage"] + ' " title="' + data.body[i]["title"] + '" />';
            html+='</div>';

        }
        html+='</div>';
        html+='<div class="swiper-pagination"></div>';
        html+='</div>';

        return html;
    }



    function buildTotalGoodsList(data){
        var html = "";

        for(var i = 0;i < data.length;i++){

            html+= '<div class="totalgoods-item" goodsId="' + data[i]["goodsId"] + '" >';

            html+= '<div class="totalgoods-item-img">';
            html+='<img src=" ' + data[i]["goodsImage"] + ' " />';
            html+= '</div>';


            html+= '<div class="totalgoods-item-intro">';


            html+='<span class="goods-title">' + data[i]["goodsTitle"]+ '</span>';


            html+= '<div class="">';


            html+= '';
            html+= '<div class="totalgoods-item-intro-s">';

            html+='<div class="pricebox">';
            html+='<span class="priceNow">￥' + data[i]["goodsPrice"]  + '</span>';
            html+='<span class="priceOrg">￥' + data[i]["goodsOldPrice"]  + '</span>';
            html+='</div>';

            // html+= '<div class="">';
            html+= '<span class="button">立即购买</span>';
            // html+= '</div>';

            html+= '</div>';


            html+= '</div>';


            html+= '</div>';




            html+= '</div>';

        }



        return html;
    }

    function buildList(data){
        var html="";
        for(var i=0;i<data.length;i++){
                html+='<div class="goods-item" goodsId="' + data[i]["goodsId"] + '">';
                html+='<div class="item-content">';

                html+='<div class="item-sec">';
                // html+='<a href="' + data[i]["detailUrl"]+"?c=web" + '">';
                html+='<img src=" ' + data[i]["goodsImage"] + ' " />';
                html+='<h3 >';
                html+='<span class="goods-title">' + data[i]["goodsTitle"]+ '</span>';
                html+='</h3>';
                html+='<div class="pricebox">';
                html+='<span class="priceNow">￥' + data[i]["goodsPrice"]  + '</span>';
                html+='<span class="priceOrg">￥' + data[i]["goodsOldPrice"]  + '</span>';
                html+='</div>';

                html+='';
                // html+='</a>';
                html+='</div>';
                html+='</div>';
                html+='</div>';
        }
        return html;
    }

    function buildTasteGoodsList(data){
        var html="";
        for(var i=0;i<data.length;i++){
            html+='<div class="goods-item" goodsId="' + data[i]["goodsId"] + '">';
            html+='<div class="item-content">';

            html+='<div class="item-sec">';
            // html+='<a href="' + data[i]["detailUrl"]+"?c=web" + '">';
            html+='<img src=" ' + data[i]["goodsImage"] + ' " />';
            html+='<h3 >';
            html+='<span class="goods-title">' + data[i]["goodsTitle"]+ '</span>';
            html+='</h3>';
            html+='<div class="pricebox">';
            html+='<span class="priceNow">申请试吃</span>';

            html+='</div>';

            html+='';
            // html+='</a>';
            html+='</div>';
            html+='</div>';
            html+='</div>';
        }
        return html;
    }


});



// 个人中心页面
$(document).on("pageInit","#pageUserCenter" ,function(e, pageId, $page) {
    var p0 = $.fn.cookie("p0");
    getUserInfor({},function (data) {

        if(data.head.errorCode=="10001"){
            $("#headImageLogin").on("click",function (e) {
                arbanbanLoad("/api/store/page/login");
            });
            $(".to-taster-page").attr("href","/api/store/page/login");
        }else{
            $("#headImageLogin").on("click",function (e) {
                arbanbanLoad("/api/store/page/mine/personal");
            });
            window.localStorage.setItem("loginShowMsg",JSON.stringify(data.body));
            window.localStorage.setItem("phoneNumber",data.body["phoneSub"]);
            window.localStorage.setItem("phoneNumberHiden",data.body["phone"]);

            $(".headImg").attr("src",data.body["headImage"]);
            $(".nickname").text(data.body["nickName"]);
            $(".authId").text(data.body["identifyAuth"] ? "已认证" : "未认证");

            if(data.body["isTaster"]==0){
                $(".to-taster-page").attr("href","/api/store/page/mine/taste");
            }else{
                window.localStorage.setItem("isTaster",data.body["isTaster"]);
                $(".to-taster-page").attr("href","/api/store/page/mine/tasteApplyResult");
            }

        }


    });


});
// 收货地址页面
$(document).on("pageInit","#pageAddress" ,function(e, pageId, $page) {
        getAddressList( {},function( data ) {
            $('.address-list').html(mineAddrListSuc(data));
            dealMineAddressList();
            $(".orders-address-infor").on("click",function (e) {

                var dt = $(this).parents(".orders-address-item").find(".addrdt").val();
                window.localStorage.setItem("selectAddr",dt);
                arbanbanLoad("/api/store/page/orders/orderSure  ")
            })
        });

        function dealMineAddressList(){
            // 收货地址删除操作
            $('.orders-addroper-delete').each(function(){
                $(this).on('click',function(){
                    var addrId = $(this).parents('.orders-address-item').attr("data-addId");
                    var obj = {
                        body : {
                            addressId:addrId
                        }
                    };
                    addressDelete(obj,function(data){

                    });
                    $(this).parents('.orders-address-item').remove();
                })
            });
            // 收货地址设置默认地址
            $('.orders-addr-default').each(function(){

                $(this).on('click',function(){
                    var addressId = $(this).parents('.orders-address-item').attr("data-addId");

                    if( $(this).hasClass('active') ){
                        $(this).removeClass('active');

                    }else{
                        $('.orders-addr-default').removeClass('active');
                        $(this).addClass('active');

                        addressSetDefault( {body:{addressId:addressId}},function(data){
                            window.location.reload();
                        });
                    }
                });
            });

            //  收货地址编辑
            $('.orders-addroper-edit').each(function(){
                $(this).on('click',function(){
                    var addrId = $(this).parents('.orders-address-item').attr("data-addId");
/*                    var objPar = {
                        addressId : addrId
                    };*/
                    window.localStorage.setItem("editaddressId",addrId);
                    arbanbanLoad("/api/store/page/mine/editAddress")

                });
            })
        }

    function mineAddrListSuc( data ){

        var html = '';
        for( var i = 0; i < data.body.length;i++){
            html+= '<div class="orders-address-item" data-addId="' + data.body[i].addressId + ' " >';

            html+= '<div class="orders-address-infor">';
            html+= '<p  class="address-name-style">'+ data.body[i].consignee + '<span>' + data.body[i].phone + '</span></p>';
            html+= '<p>' + data.body[i].address + '</p>';
            html+= '</div>';

            html+= '<div class="orders-address-operate">';
            html+= '<span class="orders-addr-default ' + (data.body[i].defaultAddress == 1 ? 'active' : '')  + ' " >' + '<i class=""></i>默认地址</span>';
            html+= '<div class="orders-addroper-state right">';
            html+= '<span class="orders-addroper-edit"><i class="icon icon-edit"></i>编辑</span>';
            html+= '<span class="orders-addroper-delete"><i class="icon icon-remove"></i>删除</span>';
            html+= '</div></div>';
            html+= '<input type="hidden" class="addrdt" value=\'' + JSON.stringify(data.body[i]) + '\' />';
            html+= '</div>';

        }
        return html;
    }


});

// 添加收货地址页面
$(document).on("pageInit","#pageAddAddress" ,function(e, pageId, $page) {

    $("#city-picker").cityPicker({
        toolbarTemplate: '<header class="bar bar-nav">\
    <button class="button button-link pull-right close-picker">确定</button>\
    <h1 class="title">选择收货地址</h1>\
    </header>'
    });

    $('#btnAddsSubmit').click(function(){

        var addr =  $("#city-picker").val().split(' ');

        var obj = {
            body:{
                consignee : $("#username").val(),
                phone : $("#usermobile").val(),
                province : addr[0],
                city :addr[1],
                county :addr[2] ? addr[2] : "",
                address : $("#useraddrd").val(),
                postCode : $("#postal").val(),
                defaultAddress : $("#defaultAdd").attr("checked") ? 1 : 0
            }

        };


        if(obj.body.consignee === ""){
            $.toast("请填写收货人姓名");
            return;
        }
        if(obj.body.phone === ""){
            $.toast("请填写手机号");
            return;
        }
        if(addr.length <= 1){
            $.toast("请选择省市区");
            return;
        }
        if(obj.body.address === ""){
            $.toast("请填写详细地址");
            return;
        }
/*        if(obj.body.postCode === ""){
            $.toast("请填写邮编");
            return;
        }*/

        saveAddress(obj,function(data){

            if(data.head.code === 1){
                arbanbanLoad("/api/store/page/mine/address")
            }
        })

    })

});

// 编辑收货地址页面
$(document).on("pageInit","#pageEditAddress" ,function(e, pageId, $page) {

    $("#city-picker").cityPicker({
        toolbarTemplate: '<header class="bar bar-nav">\
    <button class="button button-link pull-right close-picker">确定</button>\
    <h1 class="title">选择收货地址</h1>\
    </header>'
    });


    var addressId = window.localStorage.getItem("editaddressId");

    getAddressInfo({body:{addressId : addressId }},function(data){

        getContentVal( data );

        $('#btnAddsEditSubmit').on("click",function(){
            var addr =  $("#city-picker").val().split(' ');

            var obj = {

                body:{
                    addressId: addressId,
                    consignee : $("#username").val(),
                    phone : $("#usermobile").val(),
                    province : addr[0],
                    city :addr[1],
                    county :addr[2] ? addr[2] : "",
                    address : $("#useraddrd").val(),
                    postCode : $("#postal").val(),
                    defaultAddress : $("#defaultAdd").attr("checked") ? 1 : 0
                }

            };


            addressUpdate(obj,function (data) {

                if(data.head.code === 1){
                    arbanbanLoad("/api/store/page/mine/address")
                }else{
                    /*$.toast(data.head.errorCode);*/
                }

            });
        })

    });


    function getContentVal( data ){

        var consignee = data.body.consignee;
        var phone = data.body.phone;
        var province = data.body.province;
        var city = data.body.city;
        var county = data.body.county;
        var address = data.body.address;
        var county = data.body.county;
        var defaultAddress = data.body["defaultAddress"] === 1 ? true : false;
        var postCode = data.body.postCode;

        $('#username').val(consignee);
        $('#usermobile').val(phone);
        $('#city-picker').val( "" + province +" " + city + " " + county );
        $('#useraddrd').val(address);
        $('#postal').val(postCode);

        $('#defaultAdd').prop("checked",defaultAddress);






    }



});

// 个人资料页面
$(document).on("pageInit","#pagePersonal" ,function(e, pageId, $page) {

    getUserInfor({},function(data){

        $("#headImg").attr("src",data.body["headImage"]);
        $("#nickname").text(data.body["nickName"]);
        $("#gender").text(data.body["sex"] === 0 ? "男" : "女");
        $("#mobile").text(data.body["phone"]);
        $(".edit-phone").text(data.body.phone ? "修改绑定手机" : "绑定手机" );


        jQ('#fileupload').fileupload({
            url: getHost() + "/api/file/upload?msg={}",
            dataType: 'json',
            done: function (e, data) {
              $("#headImg").attr("src",data.result.body["fileUrl"]);

                var params = {
                    body : {
                        headImage :data.result.body["fileUrl"]
                    }
                };
                editUserInfo(params,function (data) {

                    if(data.head.code === 1){

                    }
                })

            }
        });



        $(".personal-mobile").on("click",function (data) {
            arbanbanLoad("/api/store/page/mine/mobileEdit")
        })


        $('.nicknamebox').on('click', function () {

            var popupHTML = buildPop("修改昵称","close-popups-name");
            $.popup(popupHTML);

            $(".personal-popup .list-block").html(buildName($("#nickname").text()));

        });


/*
        $(document).on('click','.gender', function () {
            var val = $("#gender").text();
            var popupHTML = buildPop("修改性别","close-popups-gender");
            $.popup(popupHTML);

            $(".personal-popup .list-block").html(buildGender());
            getRadioChecked(val);
        });
*/

        $(document).on('click','.gender', function () {

            var val = $("#gender").text();

            var buttons1 = [
                {
                    text: '男',
                    onClick: function() {
                        var params = {
                            body : {sex : 0}
                        };
                        editUserInfo(params,function (data) {
                            $("#gender").text("男");
                        })
                    }
                },
                {
                    text: '女',
                    onClick: function() {
                        var params = {
                            body : {sex : 1}
                        };
                        editUserInfo(params,function (data) {
                            $("#gender").text('女');
                        })
                    }
                }
            ];
            var buttons2 = [
                {
                    text: '取消',
                    bg: 'danger'
                }
            ];
            var groups = [editColor(buttons1), buttons2];
            $.actions(groups);



            function editColor(arr){
                var newArr = arr;
                for(var i = 0;i< newArr.length;i++){
                    if(val === newArr[i]["text"]){
                        newArr[i]["color"] = 'danger';
                        newArr[i]["bold"] = true;
                    }else{
                        newArr[i]["color"] = "";
                        newArr[i]["bold"] = false;
                    }

                }

                return newArr;
            }


        });

/*


        $(document).on("click",".close-popups-gender",function (e) {
            var val = getRadioVal() === "男" ? 0 : 1;

            var params = {
                body : {sex : val}
            };
            editUserInfo(params,function (data) {

                $("#gender").text(getRadioVal());
                $.closeModal(".popup");
            })
        });
*/


        $(document).on("click",".close-popups-name",function (e) {

            var  value = $("#persname").val();
            var params = {
                body : {
                    nickName :value
                }
            };
            editUserInfo(params,function (data) {

                $("#nickname").text(value);
                $.closeModal(".popup");
            })
        });

        $(document).on("click",".mine-edit-cannel",function (e) {
            $("#persname").val("")
        })

    });








    function getRadioChecked(val){
        var radioArr = document.getElementsByName("radioGender");
        for(var i=0;i<radioArr.length;i++){
            if(radioArr[i].value === val){
              radioArr[i].checked = true;
            }
        }
    }

    function getRadioVal(){
        var value = "";
        var radioArr = document.getElementsByName("radioGender");
        for(var i=0;i<radioArr.length;i++){
            if(radioArr[i].checked === true){
                value = radioArr[i].value;
            }
        }
        return value;
    }


    function buildPop(title,klass){

     var html = '';
     html+='<div class="popup personal-popup">';

        html+='<header class="bar bar-nav">';
        // html+='<a class="icon icon-left pull-left open-panel" href="javascript:history.back()"></a>';
        html+='<span class="button button-link button-nav pull-right ' + klass + '">保存</span>';
        html+='<h1 class="title">' + title + '</h1>';
        html+='</header>';
        html+='<div class="content">';
        html+='<div class="list-block media-list">';
        html+='</div>';
        html+='</div>';

        html += '</div>';


        return html;
    }

    function buildName(name){
        var html = "";
        html+='<div class="mine-name-container padtop10">';
        html+='<div class="mine-name-edit">';
        html+='<input type="text" placeholder="" value="' + name + '" id="persname" name="persname" class="cannel-aims" />';
        html+='<span class="mine-edit-cannel"></span>';
        html+='</div>';
        html+='<p class="mine-name-point">昵称不能超过10个汉字字符或20个英文字符，支持中英文、数字、下划线</p>';
        html+='</div>';
        return html;

    }


    function buildGender(){
        var html = "";
        html += '<ul>';
        html += '<li>';
        html += '<label class="label-checkbox item-content">';
        html += '<input type="radio" name="radioGender" value="男">';
        html += '<div class="item-media"><i class="icon icon-form-checkbox"></i></div>';
        html += '<div class="item-inner">';
        html += '<div class="item-subtitle">男</div>';
        html += '</div>';
        html += '</label>';
        html += '</li>';
        html += '<li>';
        html += '<label class="label-checkbox item-content">';
        html += '<input type="radio" name="radioGender" value="女">';
        html += '<div class="item-media"><i class="icon icon-form-checkbox"></i></div>';
        html += '<div class="item-inner">';
        html += '<div class="item-subtitle">女</div>';
        html += '</div>';
        html += '</label>';
        html += '</li>';
        html += '</ul>';
        return html;
    }




    $("#quit").on("click",function (e) {
        var value = $.fn.cookie('p0');

        $.fn.cookie('p0',value,{ expires : 0, path:'/' });
        arbanbanLoad("/api/store/page/login")
    })




/*
    function userInforEdit(crossDomain){
        var obj = {
            head: {
                crossDomain : "cross_editname" + crossDomain
            },
            body: {

            }
        }

        obj.body.nickName =  $('#niName').val();

        obj.body.sex =  $('#sex').val();

        editUserInfo( obj,function(data){

        });
    }*/


});






// 产品详情页面
$(document).on("pageInit","#pageGoodsDetails" ,function(e, pageId, $page) {
    $("div[name='detailTab']").each(function (i,o) {
        $(this).click(function () {
        $("div[name='detailTab']").attr("class","");
        $(this).attr("class","active");
        if($(this).attr("h-target")=="comment"){
            var cpmmentp = {
                body:{
                goodsId:window.localStorage.getItem("goodsId"),
                goodsSallType:1
                },
                head:{
                    crossDomain:"ddw"
                }
            }
            var htmlC ="";
            commentList(cpmmentp,function (data) {
                var d = data.body;
                if(d.length>0){
                    htmlC += '<ul class="list">' ;
                    $(d).each(function (i,o) {

                        htmlC +=  '<li class="item">' +
                            '<div class="info">' +
                            '<div class="author">' +
                            '<span class="nike">'+o.proxyName+'</span></div>' +
                            '<time>'+o.createTime+' </time></div><blockquote>'+o.content+'</blockquote>' ;
                            var images = o.images;
                            if(images.length!=0){
                                htmlC+= ' <div class="goodsImageInfo">';
                                $(images.split(",")).each(function (i,o) {
                                    htmlC+= '   <img onclick=\'window.open("'+o+'");\' class="goodsImage"  src="'+o+'">';
                                })
                                htmlC+= ' </div></li>';
                            }

                    })  ;

                    htmlC+= '</ul>' +
                        '<div class="loadingTarget"></div>';
                }
                $(".goods-details-wrap-intro").html(htmlC);
            })

        }else{
            getGoodsDetails("/"+window.localStorage.getItem("goodsId")+"?msg=",{},function (data) {

                $(".goods-details-wrap-intro").html(data.body);
            })
        }
        })
    })
    var todo1 = new Todo();
    var params;
    if(pageGoodsId!=""&&pageGoodsId!=undefined){
        params= {
            body:{
                goodsId:pageGoodsId,
                goodsSallType:goodsSallType
            }
        };
    }else{
        params = {
            body:{
                goodsId:window.localStorage.getItem("goodsId"),
                goodsSallType:1
            }
        };
        pageGoodsId = window.localStorage.getItem("goodsId");
    }

    var coverImage;
    // 获取产品的信息
    getGoodsInfor(params,function(data){

        pageTitle=data.body["goodsTitle"];
        pageDes=data.body["goodsDes"];
        $("title").html(data.body["goodsTitle"]);
        $(".bar-nav").find(".title").text(data.body["goodsTitle"]);
        $(".goods-details-header-intro").html(buildDetailHead(data.body));
        $(".remain_num").text(data.body["remainNum"]);
        coverImage = data.body["goodsImage"];
        // 直接购买
        $(".toBuy").on("click",function (e) {
            window.localStorage.removeItem("selectAddr");
            window.localStorage.removeItem("payAddressId");
            window.localStorage.removeItem("cartCode");
            window.localStorage.setItem("orderType",goodsSallType)
            var par = data.body;
            par["goodsNumber"] = todo1.getNumber();
            par["showTodo"] = true;
            var parArr = [];
            parArr.push(par);
            window.localStorage.setItem("goodsMsg",JSON.stringify(parArr));
            arbanbanLoad("/api/store/page/orders/orderSure");


        });


        //获取商品详情轮播图片
        goodsBannerList(mparams,function (data) {
            $(".index-banner").html(buildGoodsBanner(data));
            var swiper = new Swiper('.swiper-container', {
                direction: 'horizontal',
                loop: true,
                autoplay : 2500,
                pagination: '.swiper-pagination'
            })
        })
    });

    var mparams;
    if(pageGoodsId!=""&&pageGoodsId!=undefined){
        mparams= {
            body:{
                goodsId:pageGoodsId,
            }
        };
    }else{
        mparams = {
            body:{
                goodsId:window.localStorage.getItem("goodsId"),
            }
        };
        pageGoodsId = window.localStorage.getItem("goodsId");
    }


    function buildGoodsBanner(data){
        var html ='';

        html+='<div class="swiper-container">';
        html+='<div class="swiper-wrapper banner-list">';

        html+='<div class="swiper-slide">';
        html+='<img  src=" ' + coverImage + ' "  />';
        html+='</div>';
        for(var i = 0;i < data.body.length;i++){
            html+='<div class="swiper-slide">';
            html+='<img  src=" ' + data.body[i]["bannerImage"] + ' "  />';
            html+='</div>';
        }
        html+='</div>';
        html+='<div class="swiper-pagination"></div>';
        html+='</div>';

        return html;
    }





    // 获取产品介绍的信息
    getGoodsDetails("/"+params.body.goodsId+"?msg=",{},function (data) {

        $(".goods-details-wrap-intro").html(data.body);
    })

    getCartNumber({},function (data) {

        console.log(data);

        if(data.head.code === 1 ){
            if(data.body === 0){
                $(".iconBuy").find(".badge").text(data.body).css("opacity","0");
            }else{
                console.log("ss")
                $(".iconBuy").find(".badge").text(data.body).css("opacity","1")
            }
        }else{
            $(".iconBuy").find(".badge").text(data.body).css("opacity","0");
        }


    });
    // 加入购物车
    $(".joinbuy").on("click",function (e) {
        var params = {
            body:{
                goodsNumber : todo1.getNumber(),
                goodsId : window.localStorage.getItem("goodsId")
            }
        };
        addGoodCard(params,function (data) {
            if(data.head.code === 1){

                // $.toast("已添加至购物车");
                getCartNumber({},function (data) {
                    console.log(data);
                    $(".iconBuy").find(".badge").text(data.body).css("opacity","1")
                })

                // $(".iconBuy").find(".badge").text(todo1.getNumber()).css("opacity","1")
            }

        })
    });


    $(".content").scroll(function (e) {

        if($(this).scrollTop() >= 400){
            $(".toTop").removeClass("hide")
        }else{
            $(".toTop").addClass("hide")
        }

    });

    $(".toTop").on("click",function (e) {
        var sTop = $(".content").scrollTop();

        // $(".content").scrollTop(0);
        scrollToTop(sTop)

    })

    function scrollToTop(v){

        var top = v;
        var speed = 20;

        var timer = setInterval(function () {
            var sTop = top - speed;
            if(sTop <= 0){
                clearInterval(timer);
            }
            $(".content").scrollTop(sTop);
            top = sTop;
        },1)
    }


    //
    $(".iconBuy").on("click",function (e) {


        window.localStorage.removeItem("selectAddr");
        window.localStorage.removeItem("payAddressId");

        arbanbanLoad('/api/store/page/goods/goodsCart')
    })






    $(".todo-prev").on("click",function (e) {
        var number = $(this).parent().find(".todo-number");
        todo1.sub();
        $(this).parent().find(".todo-number").val(todo1.getNumber())
    });

    $(".todo-next").on("click",function (e) {
        var number = $(this).parent().find(".todo-number");
        todo1.add();
        $(this).parent().find(".todo-number").val(todo1.getNumber())
    });

    $(".todo-number").on("change",function () {
        var number = parseInt($(this).val());

        todo1.rand(number);
        $(this).val(todo1.getNumber())
    })





    function buildDetailHead(data){
        var html = "";
        pageImage=data["goodsImage"];
        wx.ready(function(){
            console.log("商品页面准备完成----------------------------");
            setWxEvent();
        });
      //  html+='<img src="' + data["goodsImage"] + '" />';
        html+='   <div class="index-banner">  </div>';
        html+='<div class="goods-intro">';
        html+='<div class="goods-msg">';
        html+='<h4>' + data["goodsTitle"]  + '</h4>';
        html+='<div class="pricebox">';
        html+='<span class="priceNow">￥' + data["goodsPrice"] + '</span>';
        html+='<span class="priceOrg">' + (data["goodsOldPrice"] ? "￥" + data["goodsOldPrice"] : "") + '</span>';
        // html+='<span class="discount">' + data["goodsPrice"] + '</span>';
        html+='</div>';
        html+='</div>';
        html+='<div class="share">';
        // html+='<span class="icon icon-share"></span>';
        html+='</div>';
        html+='</div>';
        return html;
    }

});

/* 订单列表页面  */
$(document).on("pageInit","#pageOrderList" ,function(e, pageId, $page) {

    getOderLists({},function(data){

        getContentHtml(data);
    });


    $(".tab-link").on("click",function (e) {
        var index = $(this).index() ;

        var orderState = index + 1;
        var params = {
            body : {
                orderState : orderState
            }
        };
        getOderLists(params,function(data){

            console.log("list::",data);
            if(data.body.length === 0){
                $("#tab" + (index + 1)).html(displayInNot());

            }else{
                $("#tab" + (index + 1)).html(buildOrderList(data.body));
            }

            dealOrderList(data);



        });

    })


    $(document).on("click",".ordersItem-dt",function () {
        var ordersId = $(this).attr("data-orderId");

        window.localStorage.setItem("orderItemId",ordersId);
        arbanbanLoad("/api/store/page/orders/ordersDetails")
    })



    function getContentHtml(data){



        if(data.head.code === 1 ){

            if( data.body.length === 0 ){
                $('.ordersList-container').html(displayInNot());
            }else{

                // $('.ordersList-container').html( payState( data.body ) );
                $('#tab1').html(buildOrderList(data.body));

            }
            dealOrderList(data)
        }else if( data.head.code === 0 && data.head.errorCode === "10001" ){
            $('.ordersList-container').html(displayInNot());
        }

    }



    function dealOrderList(data){




        $(".orders-myorder-item").each(function () {
          var childrenArr = $(this).find(".card-footer").children("span");

            if(childrenArr.length === 0){
                $(this).find(".card-footer").addClass("hide")
            }else{
                $(this).find(".card-footer").removeClass("hide");
            }

        })






        $(document).on('click','.orders-operate-pay', function () {
            var orderId = $(this).parents('.orders-myorder-item').attr("data-orderId");
            if(!is_weixin()){
                buildModal(getHost()+'/api/store/order/pay/wx/qrcode?msg={"head":{"token":"Web","openid":"fenxiao","client":"Web","versionCode":"1.0.0","deviceCode":"web","crossDomain":"cross_cartList","otherParameters":""},"body":{orderId:"'+orderId+'"}}',orderId);

            }else {

                window.location="/api/store/order/pay/wx/jsapi?orderId="+orderId;
            }

        });



        $('.orders-operate-cancel').each(function(){
            $(this).on('click',function(){

                var self = $(this);
                $.confirm('确定要取消订单?', function () {
                    var orderId = self.parents('.orders-myorder-item').attr("data-orderId");
                    cancelOrder(orderId,function(data){

                        if(data.head.code === 1){
                            self.parents('.orders-myorder-item').remove();
                            location.reload();

                        }
                    })
                });

            })




        });

        $(".orders-operate-comment").on("click",function (e) {
            var self = $(this);
            var orderId = self.parents('.orders-myorder-item').attr("data-orderId");
            window.localStorage.setItem("commentOrderId",orderId);
            arbanbanLoad("/api/store/page/orders/ordercomment")
        })
        // 删除订单
        $(".orders-operate-delete").each(function(){

            $(this).on('click',function(){
                var self = $(this);
                $.confirm('确定要删除订单?', function () {
                    var orderId = self.parents('.orders-myorder-item').attr("data-orderId");
                    deleteOrder(orderId,function(data){
                        if(data.head.code === 1){
                            self.parents('.orders-myorder-item').remove();
                        }
                    })
                });


            })
        });

        //  确认收货
        $(".orders-operate-sure").on("click",function (e) {

            var self = $(this);
            var orderId = $(this).parents('.orders-myorder-item').attr("data-orderId");

            $.confirm('是否确认收货?', function () {
                var orderId = self.parents('.orders-myorder-item').attr("data-orderId");
                confirmGoods({body : {orderId : orderId}},function (data) {
                    if(data.head.code === 1){
                        $.toast("确认成功");
                        window.location.reload();
                    }
                })
            });

        });



        // 申请退货
        $(".orders-operate-refunds").each(function(){
            $(this).on('click',function(){
                var goodsMsg = $(this).parents('li').attr("goodsMsg");
                window.localStorage.setItem("refundMsg",goodsMsg);
                arbanbanLoad("/api/store/page/orders/applyRefund")
            })
        });





        // 完善退货信息
        $(".orders-operate-refundedit").each(function(){
            $(this).on("click",function(){
                var orderRefundId = $(this).parents('li').attr("orderRefundId");
                window.localStorage.setItem("orderRefundId",orderRefundId);
                arbanbanLoad("/api/store/page/orders/compRefund")

            })
        })


        $(".orders-operate-refundCancel").on("click",function (e) {
            var orderRefundId = $(this).parents('li').attr("orderRefundId");

            var params = {
                body : {
                    orderRefundId : orderRefundId
                }
            };


            $.confirm('确定要取消退货?', function () {

                cancelRefund(params,function (data) {

                 if(data.head.code === 1){
                 $.toast("取消成功");
                 window.location.reload();
                 }
                 })


            });







        })



    }






    function buildOrderList(data){
        var html="";

        for(var i=0;i< data.length;i++){

            var state = data[i]["orderState"];

            html+='<div class="orders-myorder-item"  data-orderId="' + data[i].orderId + '">';
            html+='<div class="card">';
            html+='<div class="card-header ordersItem-dt"   data-orderId="' + data[i].orderId + '">';
            // html+='<a href="/api/store/page/orders/ordersDetails">';
            html+='<span>' + data[i].createTime  + '</span>';
            html+='<span class="orders-myorder-state">' + data[i]["stateText"]  + '</span>';
            // html+='</a>';
            html+='</div>';
            html+='<div class="card-content">';
            html+='<div class="list-block media-list">';
            html+="<ul>";
            for( var j = 0; j < data[i].orderGoodsList.length;j++ ) {

                var goodsMsg = {
                    orderId : data[i].orderId,
                    goodsId : data[i].orderGoodsList[j]["goodsId"],
                    goodsNumber :data[i].orderGoodsList[j]["goodsNumber"]
                }

                html+='<li class="" goodsMsg=\'' + JSON.stringify(goodsMsg) + '\' orderRefundId="' + (data[i].orderGoodsList[j]["orderRefundId"] ? data[i].orderGoodsList[j]["orderRefundId"] : "") + '">';
                html += '<div class="item-content">';
                html += '<div class="item-media">';
                html += '<img src="' + data[i].orderGoodsList[j].goodsImage + '" >';
                html += '</div>';
                html += '<div class="item-inner">';


                html += '';
                html += '';
                html += '<div class="orders-myorder-msg">';
                html += '<div class="item-title-row">';
                html += '<div class="item-title">' + data[i].orderGoodsList[j].goodsTitle + '</div>';
                html += '</div>';

                html += '<div class="item-subtitle">';
                html += '<span class="price">￥' + data[i].orderGoodsList[j].goodsPrice + '</span>';
                html += '<span>×' + data[i].orderGoodsList[j].goodsNumber + '</span>';
                html += '</div>';
                html += '</div>';
                html += '<div class="orders-myorder-oper">';

                if(data[i].orderGoodsList[j]["canTuihuo"]){

                    html += '<span class="orders-operate-refunds">退货</span>';
                }else if(data[i].orderGoodsList[j]["canWanshan"]){
                    html += '<span class="orders-operate-refundedit">完善退货信息</span>';
                }else if(data[i].orderGoodsList[j]["canCancelRefundGoods"]){
                    html += '<span class="orders-operate-refundCancel">取消退货</span>';
                }

                // else{

                    html += '<span class="audit">' + (data[i].orderGoodsList[j]["stateText"] ? data[i].orderGoodsList[j]["stateText"] : "") + '</span>';
                // }



                html += '</div>';


                html += '</div>';
                html += '</div>';
                html += '<div class="">';

                html += '</div>';

                html+="</li>";

            }
            html+="</ul>";
            html+='<div class="orders-payinfor-infor">';
             html+='共<span class="pay-num">' + data[i].orderGoodsTotal + '</span>件商品 &nbsp;&nbsp;';
             html+=' 合计：<span class="pay-total">￥' + data[i].orderPrice + '</span>'+ '（运费：' + data[i].orderFreight+'）';
             html+='</div>';
            html+='</div>';

            html+='</div>';


            html+='<div class="card-footer">';
            if(data[i]["canComment"]){
                html+='<span class="orders-operate-comment">评论订单</span>';
            }
            if(data[i]["canCancel"]){
                html+='<span class="orders-operate-cancel">取消订单</span>';
            }
            if(data[i]["canDelete"]){
                html+= '<span class="orders-operate-delete">删除订单</span>';
            }
            if(data[i]["canFahuo"]){

            }
            if(data[i]["canPay"]){
                html+='<span data-popup=".demo-popup" class="orders-operate-pay">去支付</span>';
            }
/*            if(data[i]["canRefundGoods"]){
                html+= '<span class="orders-operate-refund">申请退货</span>';
            }*/
            if(data[i]["canShouhuo"]){
                html+='<span class="orders-operate-sure">确认收货</span>';
            }

            html+='</div>';

            html+='</div>';
            html+='</div>';

        }

        return html;
    }



});


// 购物车页面
$(document).on("pageInit","#pageCartList" ,function(e, pageId, $page) {


    getCartList({},function (data) {

        if(data.body.length === 0 ){
            $(".goodsCart-bar").addClass("hide");
            $(".goodscart-list-wrap").html(displayInNot());
        }else{
            $(".goodsCart-bar").removeClass("hide");
            $(".goodscart-list-wrap").html(buildCartList(data.body));
        }


        $(".totalNum").text(getTotal().toFixed(2));

        $(".goodscart-items .edit").on("click",function (e) {
            if($(this).hasClass("active")){
                $(this).removeClass("active");
                $(this).text("编辑");
                $(this).parents(".goodscart-items").find(".operation").addClass("hide");
            }else{
                $(this).addClass("active");
                $(this).text("完成");
                $(this).parents(".goodscart-items").find(".operation").removeClass("hide");
            }
        });


        $(".delete").on("click",function (e) {

            var self = $(this);
            var cartId = $(this).parents(".item-content").find(".cartId").val();
            var params = { body : {cardIds : cartId}};

            deleteCart(params,function (data) {
                if(data.head.code === 1){
                    $.toast("已移出购物车");
                    self.parents(".goodscart-items").remove();
                }
            })
        });


        $(".goodscart-items .todo-prev").on("click",function (e) {

            var goodsId = $(this).parents(".goodscart-items").attr("goodsId");
            var number = parseInt($(this).parent().find(".todo-number").val());
            var goodsNumber = number - 1;
            var params = {
                body :{}
            };
            if(number === 1 ){

                $.toast("不能再少了....");
                return false;
            }
            params.body["goodsId"] = goodsId;
            params.body["goodsNumber"] = goodsNumber;
            var self =  $(this);
            operateGooodsNumber(params,function (data) {
                self.parent().find(".todo-number").val(goodsNumber);
                self.parents(".goodscart-items").find(".number").text("×" + goodsNumber);
                var total = parseFloat(self.parents(".goodscart-items").attr("price")) * goodsNumber;
                self.parents(".goodscart-items").find(".hiddenInput").val(total);

                $(".totalNum").text(getTotal().toFixed(2));
            })

        });

        $(".goodscart-items .todo-next").on("click",function (e) {
            var params = {
                body :{}
            };
            var goodsId = $(this).parents(".goodscart-items").attr("goodsId");
            var number = parseInt($(this).parent().find(".todo-number").val());
            var goodsNumber = number + 1;
            params.body["goodsId"] = goodsId;
            params.body["goodsNumber"] = goodsNumber;
            var self =  $(this);
            operateGooodsNumber(params,function (data) {
                self.parent().find(".todo-number").val(goodsNumber);
                self.parents(".goodscart-items").find(".number").text("×" + goodsNumber);
                var total = parseFloat(self.parents(".goodscart-items").attr("price")) * goodsNumber;
                self.parents(".goodscart-items").find(".hiddenInput").val(total);

                $(".totalNum").text(getTotal().toFixed(2));
            })

        });


        $(".goodscart-items").each(function () {
            var input = $(this).find(".check");

            input.on("change",function (e) {

                if($(this).attr("checked")){
                    $(this).parents(".goodscart-items").find(".hiddenInput").addClass("totalMon");
                    $(this).parents(".goodscart-items").find(".cartIdbox").addClass("cartId");
                    $(this).parents(".goodscart-items").find(".goodsListbox").addClass("goodsList");
                }else{
                    $(this).parents(".goodscart-items").find(".hiddenInput").removeClass("totalMon");
                    $(this).parents(".goodscart-items").find(".cartIdbox").removeClass("cartId");
                    $(this).parents(".goodscart-items").find(".goodsListbox").removeClass("goodsList");
                }
                $(".totalNum").text(getTotal().toFixed(2))

            })
        });


        $(".btnSubmitBuy").on("click",function (e) {
            var total = $(".totalNum").text();
            var cardIds = getCartIds();
            var goodsList = getGoodsList();

            window.localStorage.setItem("DTCartIds",cardIds);
            window.localStorage.setItem("goodsMsg",JSON.stringify(goodsList));
            window.localStorage.setItem("cartCode","1");
        })

    });


    function getTotal(){
        var total = 0;
        $(".totalMon").each(function () {
            var val = parseFloat($(this).val());
            total+= val;
        });
        return total;
    }
    function getCartIds(){
        var total = [];
        $(".cartId").each(function () {
            var val = $(this).val();
            total.push(val)
        });
        return total.join(",");
    }

    function getGoodsList(){
        var total = [];
        $(".goodsList").each(function () {
            var val = JSON.parse($(this).val());
            total.push(val)
        });
        return total;
    }






    function buildCartList(data){
        var html="";
        html+="<ul>";
        for(var i = 0; i<data.length;i++){

            html+='<li class="goodscart-items" price="' + data[i]["goodsPrice"] + '" goodsId="' + data[i]["goodsId"] + '">';
            html+='<div class="goodscart-items-header">';
            html+='<p class="edit">编辑</p>';
            html+='</div>';
            html+='<div class="item-content">';
            html+='<label class="label-checkbox">';
            html+='<input class="check" type="checkbox" name="checkbox" checked >';
            html+='<div class="item-media"><i class="icon icon-form-checkbox"></i></div>';

            html+='</label>';
            html+='<div class="item-inner">';

            html+='<div class="intro">';

            html+='<div class="images">';
            html+='<img src="' + data[i]["goodsImage"] + '" />';
            html+='</div>';

            html+='<div class="text">';
            html+='<h5>' + data[i]["goodsTitle"] + '</h5>';
            html+='<div class="extra">';
            html+='<span class="price">￥' + data[i]["goodsPrice"] + '</span>';
            html+='<span class="number">×' + data[i]["goodsNumber"] + '</span>';
            html+='</div>';
            html+='</div>';

            html+='</div>';


            html+=' <div class="operation hide">';
            html+='<div class="par">';
            html+='<div class="todo">';
            html+='<span class="todo-prev">-</span>';
            html+='<input class="todo-number" type="text" value="' + data[i]["goodsNumber"] + '" />';
            html+='<span class="todo-next">+</span>';
            html+='</div>';
            html+='</div>';
            html+='<div class="delete">';
            html+='删除';
            html+='</div>';
            html+='</div>';
            html+='</div>';
            html+='<input type="hidden" class="hiddenInput totalMon" value="' + (data[i]["goodsNumber"] * data[i]["goodsPrice"] ) + '" />';
            html+='<input type="hidden" class="cartIdbox cartId" value="' + data[i]["cardId"]  + '" />';
            html+='<input type="hidden" class="goodsListbox goodsList" value=\'' + JSON.stringify(data[i]) + '\' />';
            html+='</div>';
            html+='</li>';
        }

        html+="</ul>";
        return html;

    }


});
var canClick=true;
// 直接下单订单确认
$(document).on("pageInit","#pageOrderSure" ,function(e, pageId, $page) {

    if(window.localStorage.getItem("selectAddr")){
        var addrs = JSON.parse(window.localStorage.getItem("selectAddr"));

        window.localStorage.setItem("payAddressId",addrs["addressId"]);
        window.localStorage.removeItem("selectAddr");
        $(".addresswrap").html(bulidHasAddress(addrs));
    }else{
        getAddressDefault({},function(data){
            if(data.head.code === 1){
                $(".addresswrap").html(bulidHasAddress(data.body));
                window.localStorage.setItem("payAddressId",data.body["addressId"]);

            }else if(data.head.code === 0){
                if(data.head.errorCode === "10002"){
                    $(".addresswrap").html(bulidNotAddress(data.body))
                }
            }
        });
    }

    var goodsList = JSON.parse(window.localStorage.getItem("goodsMsg"));

    $(".goodsMsg").html(buildGoodsList(goodsList));
    $(".orderTotal").text("￥" + calcTotal(goodsList));


    $(".ordersure-goodsmsg-todo .todo-prev").on("click",function (e) {

        var goodsId = $(this).parents("li").attr("goodsId");
        var number = parseInt($(this).parent().find(".todo-number").val());

        var goodsNumber = number - 1;
        if(number === 1 ){
            $.toast("不能再少了....");
            return false;
        }
        var self =  $(this);

        self.parent().find(".todo-number").val(goodsNumber);
        self.parents("li").find(".number").text("×" + goodsNumber);

        var total = parseFloat(self.parents("li").attr("price")) * goodsNumber;
        self.parents("li").find(".hiddenInput").val(total);
        $(".orderTotal").text("￥"+ total.toFixed(2));
    });

    $(".ordersure-goodsmsg-todo .todo-next").on("click",function (e) {

        var goodsId = $(this).parents("li").attr("goodsId");
        var number = parseInt($(this).parent().find(".todo-number").val());
        var goodsNumber = number + 1;
        var self =  $(this);
        self.parent().find(".todo-number").val(goodsNumber);
        self.parents("li").find(".number").text("×" + goodsNumber);
        var total = parseFloat(self.parents("li").attr("price")) * goodsNumber;
        self.parents("li").find(".hiddenInput").val(total);
        $(".orderTotal").text("￥"+ total.toFixed(2));



    });



    $("#toPay").on("click",function (e) {
        if(canClick){
            canClick =false;
                var params = {
                    body : {}
                };

                params.body["orderType"] = window.localStorage.getItem("orderType");
                if(window.localStorage.getItem("cartCode") === "1"){
                    params.body["shippingAddressId"] = window.localStorage.getItem("payAddressId");
                    params.body["cardIds"] = getCartId(goodsList);

                    if( params.body["shippingAddressId"] === "" || params.body["shippingAddressId"] === null){
                        $.toast("请选择收货地址");
                        return ;
                    }else{
                        createOrder("/api/store/order/fenxiao/make/card",params);
                    }
                }else {
                    params.body["shippingAddressId"] = window.localStorage.getItem("payAddressId");
                    // params.body["goodsNumber"] = getGoodsNumber(goodsList);
                    params.body["goodsNumber"] = $(".todo-number").val();
                    params.body["goodsId"] = getGoodsId(goodsList);
                    if( params.body["shippingAddressId"] === "" || params.body["shippingAddressId"] === null ){
                        $.toast("请选择收货地址");
                        return ;
                    }else{
                        createOrder("/api/store/order/fenxiao/make",params);
                    }
                }
        }
    });




    function createOrder(url,params) {

        placeOrder(url,params,function (data) {
            canClick = true;
            if(data.head.code===1){
                window.localStorage.removeItem("payAddressId");
                window.localStorage.removeItem("cartCode");
                if(!is_weixin()){
                    buildModal(getHost()+'/api/store/order/pay/wx/qrcode?msg={"head":{"token":"Web","openid":"fenxiao","client":"Web","versionCode":"1.0.0","deviceCode":"web","crossDomain":"cross_cartList","otherParameters":""},"body":{orderId:"'+data.body.orderId+'"}}',data.body.orderId);
                }else {
                    window.location="/api/store/order/pay/wx/jsapi?orderId="+data.body.orderId;         }
            }else{
                $.toast(data.head.message);
            }

        })


    }
    
    function calcTotal(data){
        var total = 0;
        data.forEach(function (value,index) {
            total += (parseFloat(value["goodsPrice"]) * parseFloat(value["goodsNumber"]))
        })

        return total.toFixed(2);
    }



    function getCartId(data){
        var goodsId = [];
        for(var i = 0;i < data.length;i++){
            goodsId.push(data[i]["cardId"])
        }
        return goodsId.join(",")
    }

    function getGoodsId(data){
        var goodsId = [];
        for(var i = 0;i < data.length;i++){
            goodsId.push(data[i]["goodsId"])
        }

        return goodsId.join()
    }

    function getGoodsNumber(data){
        var number = 0;
        for(var i = 0;i < data.length;i++){
            number += data[i]["goodsNumber"]
        }
        return number;
    }




    function buildGoodsList(data){
        var html="";
        html+='<div class="card">';
        html+='<div class="card-header">';
        html+='订单详情';
        html+='</div>';
        html+='<div class="card-content">';
        html+='<div class="list-block media-list">';
        html+='<ul>';
        html+='';
        for(var i = 0;i<data.length;i++){

            html+='<li goodsId="' + data[i]["goodsId"] + '" price="' + data[i]["goodsPrice"] + '">';
            html+='<div class="item-content">';
            html+='<div class="item-media">';
            html+='<img src="' + data[i]["goodsImage"]  + '" >';
            html+='</div>';
            html+='<div class="item-inner">';
            html+='<div class="item-title-row">';
            html+='<div class="item-title">' + data[i]["goodsTitle"] + '</div>';
            html+='</div>';
            html+='<div class="item-subtitle">';
            html+='<span class="price">￥' + data[i]["goodsPrice"] + '</span>';
            html+='<span class="number">×' + data[i]["goodsNumber"] + '</span>';
            html+='</div>';
            html+='</div>';
            html+='</div>';

           if(window.localStorage.getItem("orderType")==2){
               if(data[i]["showTodo"]){
                   html+='<div class="ordersure-goodsmsg-oper">';
                   html+='<div class="ordersure-goodsmsg-todo">';
                   html+='<span>购买数量</span>';
                   html+='<div class="todo"><span class="todo-prev">-</span><input class="todo-number" type="text" value="' + data[i]["goodsNumber"] + '" /><span class="todo-next">+</span></div>';
                   html+='</div>';
                   html+='';
                   html+='';
                   html+='</div>';
               }
           }else{
               html+='<input class="todo-number" type="hidden" value="' + data[i]["goodsNumber"] + '" />';
           }




            html+='</li>';

        }
        html+='</ul>';
        html+='</div>';
        html+='';
        html+='';
        html+='';
        html+='</div>';
        html+='</div>';
        return html;
    }


    function bulidNotAddress(data){
        var html="";

        html+='<div class="card">';

        html+='<a class="card-header" href="/api/store/page/mine/address">';
        html+='';
        html+='<span>添加地址</span>';
        html+='<span class="icon icon-right"></span>';
        html+='';
        html+='</a>';

        html+='</div>';
        return html;

    };
    
    function bulidHasAddress(data) {
        var html = "";
        html+='<div class="card">';
        html+='<a class="card-header" href="/api/store/page/mine/address">';
        html+='';
        html+='<span>收货地址</span>';
        html+='<span class="icon icon-right"></span>';
        html+='';
        html+='</a>';
        html+='<div class="card-content">';
        html+='<div class="card-content-inner">';
        html+='<div class="addsMsg">';
        html+='<div class="addsMsg-item">';
        html+='<span>收货人：</span>';
        html+='<span>' + data["consignee"] + '</span>';
        html+='</div>';
        html+='<div class="addsMsg-item">';
        html+='<span>收货地址：</span>';
        html+='<span>' + data["province"] + data["city"] + data["county"] + data["address"] + '</span>';
        html+='</div>';
        html+='<div class="addsMsg-item">';
        html+='<span>邮编：</span>';
        html+='<span>' + data["postCode"] + '</span>';
        html+='</div>';
        html+='</div>';
        html+='</div>';
        html+='</div>';
        html+='</div>';

        return html;
    }

});

// 订单详情页面
$(document).on("pageInit","#pageOrderDetails" ,function(e, pageId, $page) {


    var orderId = window.localStorage.getItem("orderItemId");

        getOrdersDetail({body:{orderId:orderId}},function(data){

            dealOrdersDetail(data);

        })


    function dealRefundDetail(data){


        //data.body.orderState = "5";

        //  订单详情 --生成头部订单状态展示
        $('.orders-details-state-box').html( getStateRefundBanner(data) );


        if(data.body.orderState == judgeOrderState.refund.receiptSuring){

            $('.orders-myorder-operate').parent(".common-footer-container").remove();
            $(".common-container").addClass("clearBottom");
        }else{

            // 订单详情 -- 生成底部订单支付状态以及相关处理的
            $('.orderDetails-bar').html( getStateRefundfooter( data ) );
        }


        // $('.orders-refund-statebox').html(  getStateRefundDetail(data) );




    }





    function getStateRefundDetail(data){


        var html="";
        html+='<div class="orders-refund-state">';
        html+='<h3 class="orders-refund-state-title">退款状态</h3>';
        html+='<div class="orders-refund-state-box">';

        for(var i = 0; i < data.body.length;i++){

            html+='<div class="orders-refund-state-item">';
            html+='<h4>' + data.body[i].time;
            html+=' <span class="">' ;
            html+= judgeOrderState.check["" + data.body[i].type ] + '</span></h4>';
            html+='<div class="orders-state-situation">';
            html+='<p>' + data.body[i].message + '</p>';
            html+='</div>';
            html+='</div>';
        }

        html+='</div>';
        html+='</div> ';

        return html;

    }









    function dealOrdersDetail(data){

        //data.body.orderState = "113";
        getContentHtml(data);

        dealOrderDetailOperation(data);



    }


    function operLIst(data){
        var html="";
        if(data["canCancel"]){
            html+='<span class="orders-operate-cancel">取消订单</span>';
        }
        if(data["canComment"]){
            html+='<span class="orders-operate-comment">评论</span>';
        }
        if(data["canDelete"]){
            html+= '<span class="orders-operate-delete">删除订单</span>';
        }
        if(data["canFahuo"]){

        }
        if(data["canPay"]){
            html+='<span class="orders-operate-pay open-popup">去支付</span>';
        }
/*        if(data["canRefundGoods"]){
            html+= '<span class="orders-operate-refund">申请退货</span>';
        }*/
        if(data["canShouhuo"]){
            html+='<span class="orders-operate-sure">确认收货</span>';
        }

        return html;
    }

    function dealOrderDetailOperation(data){

        var orderId = window.localStorage.getItem("orderItemId");



        // 订单操作 -- 订单删除操作
        $(".orders-operate-delete").on('click',function(){

            var self = $(this);
            $.confirm('确定要删除订单?', function () {
                deleteOrder(orderId,function(data){
                    if(data.head.code === 1){
                        history.back();
                        // arbanbanLoad("/api/store/page/orders/orderList")
                    }
                })
            });
            })


        // 订单操作 -- 申请退款操作
        $(".orders-operate-refund").on("click",function(){

            var state = data.body.orderState.replace(/\s+/g, "").split("");

            if( state[0] == 1    ){

                if(  state[1] == 0 || (state[1] == 1  && state[2] == 0 ) ){
                    cancelOrders({body:{orderId:orderId}},function(data){})
                }else{
                    window.location = "orders_details_apply.html" + urlPassVal({orderId:orderId});
                }

            }

        })

/*        // 订单操作 -- 添加退货信息操作
        $(".orders-operate-addrefund").on("click",function(){
            window.location = "orders_refund_msg.html" + urlPassVal({orderId:orderId});
        })*/


        //
        $(".orders-operate-cancel").on("click",function (e) {
            var self = $(this);
            $.confirm('确定要取消订单?', function () {
                cancelOrder(orderId,function(data){
                    if(data.head.code === 1){
                        window.location.reload();
                        // arbanbanLoad("/api/store/page/orders/orderList")
                    }
                })
            });
        })
        $(".orders-operate-comment").on("click",function (e) {
            window.localStorage.setItem("commentOrderId",orderId);
            arbanbanLoad("/api/store/page/orders/ordercomment")
        });


        // 去支付
        $(".orders-operate-pay").on("click",function (e) {

           if(!is_weixin()){

                buildModal(getHost()+'/api/store/order/pay/wx/qrcode?msg={"head":{"token":"Web","openid":"fenxiao","client":"Web","versionCode":"1.0.0","deviceCode":"web","crossDomain":"cross_cartList","otherParameters":""},"body":{orderId:"'+orderId+'"}}',orderId);

            }else {

               window.location="/api/store/order/pay/wx/jsapi?orderId="+orderId;    }


        })


        $(".orders-operate-sure").on("click",function (e) {

            $.confirm('是否确认收货?', function () {
                confirmGoods({body : {orderId : orderId}},function (data) {
                    if(data.head.code === 1){
                        $.toast("确认成功");
                        window.location.reload();
                    }
                })
            });


        })


    }

    function getContentHtml( data ){



        // var state = data.body.orderState;

        //  订单详情 --生成头部订单状态展示
        $('.orders-details-state-box').html( getStateBanner( data.body ) );


        // 订单详情 -- 生成订单基本信息，以及收货信息的html代码
        $('.orders-details-info').html( getStateOrderInfo(data) );

        // 订单详情 -- 生成物流信息
        getTransportLog({body:{orderId:orderId}},function( data1 ){

            $('.orders-myorder-logistics').html( getStateTransport( data1,data ) );

            $('.myorder-logistics-nav').on('click',function(){
                $(this).next('.myorder-logistics-box').toggle();
            });

        });

        // 订单详情 -- 生成订单中的商品信息
        $('.orders-myorder-list').html(getStateGood(data.body));



        $(".orderDetails-bar").html(operLIst(data.body))

    }


    /**
     * 订单状态-无
     *
     */
    function  getContentInNull() {
        var html="";
        html+='<div class="orders-null-container">';
        html+='<img class="orders-null-img404" src="../images/orders/orders_null.png" />';
        html+='<h3 class="orders-null-tip">您还没有订单哦!</h3>';
        html+='<span class="orders-null-go">去逛逛</span>';
        html+='</div>';

        return html;

    }









});



// 申请退货的页面

$(document).on("pageInit","#pageApplyRefund" ,function(e, pageId, $page) {

    var refundMsg = JSON.parse(window.localStorage.getItem("refundMsg"));
    $(".number").text(refundMsg["goodsNumber"])


    jQ('#fileupload').fileupload({
         url: getHost() + "/api/file/upload?msg={}",
         dataType: 'json',
         done: function (e, data) {

            var node = "<div class='proof-item'>";
            node += '<img src="' + data.result.body["fileUrl"] + '" />';
            node +='</div>';
            $(".proof-list").prepend(node);
         },
         progressall: function (e, data) {
               var progress = parseInt(data.loaded / data.total * 100, 10);

         }
     });


    $("#submit").on("click",function (e) {

        var params = {
            body : {}
        };


        if( parseInt($("#refundGoodsNumber").val()) > parseInt(refundMsg["goodsNumber"]) ){
            $.toast("超过可退货的最大数量");
            return ;
        }

        params.body["refundGoodsNumber"] = ($("#refundGoodsNumber").val() >= refundMsg["goodsNumber"] ? refundMsg["goodsNumber"] : $("#refundGoodsNumber").val() );
        params.body["orderGoodsId"] =refundMsg["goodsId"];
        params.body["orderId"] =refundMsg["orderId"];
        params.body["voucher"] = getVoucher();
        params.body["refundCase"] = $("#refundCase").val();
        params.body["refundNotes"] = $("#refundNotes").val();



        applyRefundGood(params,function(data) {

            if(data.head.code === 1){
                $.toast("提交成功");
                window.localStorage.removeItem("refundMsg");
                arbanbanLoad("/api/store/page/orders/orderList");
            }
        })



    });

    function getVoucher(){

        var voucher = [];
        $(".proof-item").each(function () {

            voucher.push($(this).find("img").attr("src"));
        })

        return voucher.join(",");
    }



});
function buildComment(goodsId,goodsImage) {
var html = '<ul goodsId="'+goodsId+'" name="goodsId"><li class="item-content"><div class="item-media"><i class="icon icon-f7"></i></div><div class="item-inner"><div class="item-title">商品</div><div class="item-after"><img class="goodsImage" src="'+goodsImage+'"></div></div></li><li class="item-content" grade="grade_taste"><div class="item-media"><i class="icon icon-f7"></i></div><div class="item-inner"><div class="item-title">产品口感</div><div class="item-after"><label class="comment-label comment-label-select" v="1">暖</label><label class="comment-label comment-label-noselect" v="2">中</label><label class="comment-label comment-label-noselect" v="3">差</label></div></div></li><li class="item-content" grade="grade_pack"><div class="item-media"><i class="icon icon-f7"></i></div><div class="item-inner"><div class="item-title">产品包装</div><div class="item-after"><label class="comment-label comment-label-select" v="1">暖</label><label class="comment-label comment-label-noselect" v="2">中</label><label class="comment-label comment-label-noselect" v="3">差</label></div></div></li><li class="item-content" grade="grade_fresh"><div class="item-media"><i class="icon icon-f7"></i></div><div class="item-inner"><div class="item-title">新鲜度</div><div class="item-after"><label class="comment-label comment-label-select" v="1">暖</label><label class="comment-label comment-label-noselect" v="2">中</label><label class="comment-label comment-label-noselect" v="3">差</label></div></div></li><li class="item-content" grade="grade_clean"><div class="item-media"><i class="icon icon-f7"></i></div><div class="item-inner"><div class="item-title">干净度</div><div class="item-after"><label class="comment-label comment-label-select" v="1">暖</label><label class="comment-label comment-label-noselect" v="2">中</label><label class="comment-label comment-label-noselect" v="3">差</label></div></div></li><li class="align-top"><div class="item-content"><div class="item-media"><i class="icon icon-form-comment"></i></div><div class="item-inner"><div class="item-title label">评论</div><div class="item-input"><textarea name="comment"></textarea></div></div></div></li><div class="card left20"><div class="card-header"><div class="item-title">                            评论图片<span class="asterisk">*</span></div></div><div class="card-content"><div class="card-content-inner"><div class="proof-list"><div class="proof-upload"><input type="file" accept="image/*" name="fileupload"  /></div></div></div></div></div></ul>';

return html;
}
$(document).on("pageInit","#pageCommnet" ,function(e, pageId, $page) {
    var orderId = window.localStorage.getItem("commentOrderId");
    var pc = {
        body:{orderId:orderId}
    }
    canCommentGoods(pc,function (data) {
        if(data.head.code==1){
           var listGoods =  data.body;
           var html = '';
           $(listGoods).each(function (i,o) {
               html+=buildComment(o.goodsId,o.goodsImage);
           });
            $("#commentHtml").html(html);
            $(".comment-label").click(function () {
                $(this).parent().find(".comment-label").attr("class","comment-label comment-label-noselect");
                $(this).attr("class","comment-label comment-label-select");
            });
            jQ('input[name="fileupload"]').fileupload({
                url: getHost() + "/api/file/upload?msg={}",
                dataType: 'json',
                done: function (e, data) {

                    var node = "<div class='proof-item'>";
                    node += '<img src="' + data.result.body["fileUrl"] + '" />';
                    node +='</div>';
                    $(this).parent().parent().prepend(node);
                },
                progressall: function (e, data) {
                    var progress = parseInt(data.loaded / data.total * 100, 10);

                }
            });

        }
    })

    $("#save").click(function () {
       var listComment=[];

        $("ul[name='goodsId']").each(function (i,o) {
            var comment = {};
            var goodsId = $(this).attr("goodsId");
            comment.goodsId = goodsId;
            comment.gradeTaste=$(this).find("li[grade='grade_taste']").find(".comment-label-select").eq(0).attr("v");
            comment.gradeFresh=$(this).find("li[grade='grade_fresh']").find(".comment-label-select").eq(0).attr("v");
            comment.gradePack=$(this).find("li[grade='grade_pack']").find(".comment-label-select").eq(0).attr("v");
            comment.gradeClean=$(this).find("li[grade='grade_clean']").find(".comment-label-select").eq(0).attr("v");
            comment.comment=$(this).find("textarea[name='comment']").eq(0).val();
            var voucher = [];
            $(this).find(".proof-item").each(function () {

                voucher.push($(this).find("img").attr("src"));
            })
            comment.orderId = orderId;
            comment.images=voucher.join(",");
            listComment.push(comment);
        });
        var param={
            body:{comments:listComment,orderId:orderId},
            head:{crossDomain:"ooooo"}
        };
        addComment(param,function (data) {
            if(data.head.code === 1){
                $.toast("提交成功");
                arbanbanLoad("/api/store/page/orders/orderList");
            }else{
                $.toast(data.head.message);
            }
        });
    });



    function getVoucher(){

        var voucher = [];
        $(".proof-item").each(function () {

            voucher.push($(this).find("img").attr("src"));
        })

        return voucher.join(",");
    }



});




$(document).on("pageInit","#pageUpdateRefundMsg" ,function(e, pageId, $page) {


    
    $("#submit").on("click",function (e) {
        var params = {
            body : {}
        }
        params.body = JSON.parse($("#hidden").val());
        params.body["expressNumber"] = $("#expressNumber").val();
        params.body["expressCompany"] = $("#expressCompany").val();
        params.body["orderId"] = window.localStorage.getItem("orderRefundId");



        updateRefundMsg(params,function(data){

            if(data.head.code === 1){

                window.localStorage.removeItem("orderRefundId");
                arbanbanLoad("/api/store/page/orders/orderList");
            }
        })
    })
    
});



$(document).on("pageInit","#pageOpinion" ,function(e, pageId, $page) {



    $(document).on("click","#submit",function (e) {

        // if($("#content").val().length !== 0 &&  $("#contactInfo").val().length !== 0  ){
            var params = {
                body : {
                    contactInfo  : $("#content").val(),
                    content : $("#contactInfo").val()
                }
            }

        if($("#content").val() === ""){
            $.toast("请留下您的宝贵意见，谢谢");
            return;
        }
        if($("#contactInfo").val() === ""){
            $.toast("请留下您的联系方式，以便于联系您");
            return;
        }


        toFeedback(params,function (data) {
            var code = data.head.code;
            if (code === 1) {
                $.toast("提交成功");
            }
        })




        // }else{
        //     if ($("#content").val().length == 0) {
        //         return false
        //     }
        //     if($("#contactInfo").val().length == 0){
        //         $(".toast").text("请填写您的联系方式").fadeIn(500).delay(1500).fadeOut(400)
        //     }
        // }

    })
});

// 个人-试吃系统
$(document).on("pageInit","#PageTaste" ,function(e, pageId, $page) {

    var isClick = true;
    $(".verify").on("click",function () {

        if(!isClick){
            return false;
        }
        var obj = {
            body:{
                phone:$("#mobile").val()
            }
        };

        var self = $(this);
        var seconds = 60;
        if(validatemobile(obj.body.phone)){
            isClick = false;
            var setSencend = setInterval(function(e){
                seconds--;
                self.text( seconds + "s重新发送" );
                if( seconds < 1){
                    isClick = true;
                    self.text( "发送验证码" );
                    clearInterval(setSencend);
                }
            },1000);

            getVerifyCodes(obj);


        }else{
            $.toast("手机号码不能为空");
        }
    });


    $("#applytasterbtn").on("click", function (){

        var obj = {
            body: {
                true_name: $("#true_name").val(),
                mobile: $("#mobile").val(),
                verify: $("#verify").val(),
                identify_number: $("#identify_number").val()
            }
        };

        if (validatemobile(obj.body.mobile)  && obj.body.verify !== "" && obj.body.true_name !== "" && isIDCardNo(obj.body.identify_number)) {
            applyTaster(obj, function(data){
                if (data.head.code === 1) {
                    window.localStorage.setItem("isTaster",1);
                    $.toast("提交成功!");
                } else {
                    $.toast(data.head.message);
                }
            });
        } else {
            if (obj.body.true_name === "") {
                $.toast("真实姓名不能为空");
            } else if (!validatemobile(obj.body.mobile)) {
                $.toast("手机号码格式不正确，请重新填写");
            } else if (obj.body.verify === "") {
                $.toast("验证码不能为空");
            } else if (obj.body.identify_number === "") {
                $.toast("身份证不能为空");
            }
        }

    });
});




// 个人-试吃系统结果
$(document).on("pageInit","#PageApplyTasterResu" ,function(e, pageId, $page) {
    var  isTaster = window.localStorage.getItem("isTaster");
    if(isTaster==1){
        $(".taste-apply-result-message").text("您已经提交申请，请耐心等待!");
    }else if(isTaster==2){
        $(".taste-apply-result-message").text("您已经成为品鉴师，欢迎品尝我们的产品！");
    }else if(isTaster==3){
        $(".taste-apply-result-message").text("很抱歉，您没审核没通过审核，如有疑问，请联系客服！");
    }else{
        $(".taste-apply-result-message").text("很抱歉，您已经被禁止申请，如有疑问，请联系客服！");
    }
});




/**
 * 身份证格式验证函数
 * @param card
 * @returns {boolean}
 */
function isIDCardNo(card)
{
    // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
    var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    if(reg.test(card) === false)
    {
        $.toast("身份证输入不合法");
        return  false;
    }

    return true;
}




$(document).on("pageInit","#pageMessage" ,function(e, pageId, $page) {

    var params = {
    }

    messageList(params,function (data) {

        if(data.head.code === 1){
            if(data.body.length === 0){
                $(".problem-list").html( displayInNot() );
            }else{
                $(".problem-list").html(buildMessage(data.body));
            }
        }



        $(".problem-list").find("li").on("click",function (e) {
            var id = $(this).attr("id");
            window.localStorage.setItem("messageDetailId",id);
            arbanbanLoad("/api/store/page/mine/messageDetail")


        })

    })

    function buildMessage(data){
        var html = "";
        for(var i = 0; i< data.length;i++){
            html+='<li id="' + data[i]["messageId"] + '"><span>' + data[i]["messageTitle"] + '</span><span class="icon icon-right"></span></li>';
        }
        return html;

    }

});

$(document).on("pageInit","#pageMessageDetail" ,function(e, pageId, $page) {

    var params = {
        body : {
            messageId : window.localStorage.getItem("messageDetailId")
        }
    }
    messageDetail(params,function (data) {

        $("title").text(data.body["messageTitle"]);
        $(".bar-nav").find(".title").text(data.body["messageTitle"]);
        $(".problemDetail-container").html(buildProDet(data.body))
    })


    function buildProDet(data) {
        var html='';
        html+='<div class="problemDetail-header">';
        html+='<h3>' + data["messageTitle"] + '</h3>';
        html+='<p>' + data["createTime"] + '</p>';
        html+='</div>';
        html+='<div class="problemDetail-content">';
        html+='' + data["messageContent"] + '';
        html+='</div>';
        return html;
    }
});


$(document).on("pageInit","#pageProblem" ,function(e, pageId, $page) {

    var params = {
        body : {
            type : 1
        }
    }

    toQuestionList(params,function (data) {

        if(data.head.code === 1){
            if(data.body.length === 0){
                $(".problem-list").html( displayInNot() );
            }else{
                $(".problem-list").html(buildProb(data.body));
            }
        }



        $(".problem-list").find("li").on("click",function (e) {
            var id = $(this).attr("id");

            window.localStorage.setItem("problemDetailId",id);
            arbanbanLoad("/api/store/page/mine/problemDetail")

            
        })

    })

    function buildProb(data){
        var html = "";
        for(var i = 0; i< data.length;i++){
            html+='<li id="' + data[i]["id"] + '"><span>' + data[i]["title"] + '</span><span class="icon icon-right"></span></li>';
        }
        return html;

    }

});

$(document).on("pageInit","#pageProblemDetail" ,function(e, pageId, $page) {

    var params = {
        body : {
            id : window.localStorage.getItem("problemDetailId")
        }
    }
    getQuestionDetail(params,function (data) {

        $("title").text(data.body["title"]);
        $(".bar-nav").find(".title").text(data.body["title"]);
        $(".problemDetail-container").html(buildProDet(data.body))
    })


    function buildProDet(data) {
        var html='';
        html+='<div class="problemDetail-header">';
        html+='<h3>' + data["title"] + '</h3>';
        html+='<p>' + data["createTime"] + '</p>';
        html+='</div>';
        html+='<div class="problemDetail-content">';
        html+='' + data["content"] + '';
        html+='</div>';
        return html;
    }
});
$(document).on("pageInit","#pageMobileEdit" ,function(e, pageId, $page) {


    var isClick = true;

    $(".verify").on("click",function () {

        if(!isClick){
            return false;
        }

        var obj = {
            body:{
                phone:$("#mobile").val(),
                businessUri:"/api/store/phone/bind",
                validateType:1,
                source:"proxy"
            }
        };

        var self = $(this);
        var seconds = 60;
        if(validatemobile(obj.body.phone)){


            getVerifyCode(obj,function(data){
                isClick = false;
                if(data.head.code===1){

                    var setSencend = setInterval(function(e){
                        seconds--;
                        self.text( seconds + "s重新发送" );
                        if( seconds < 1){
                            isClick = true;
                            self.text( "发送验证码" );
                            clearInterval(setSencend);
                        }
                    },1000);
                }else {
                    $.toast(data.head.message)
                }

            })


        }else{
            $.toast("手机号码不能为空");
        }


    });

    $("#submit").on("click",function (e) {

        var params = {
            body:{
                phone:$("#mobile").val(),
                verificationCode:$("#verify").val()
            }
        };
        bindMobile(params,function (data) {

            if(data.head.code === 1){
                $.toast("绑定成功");
            }else{
                $.toast(data.head.message);
            }

        })
    })





});

/*


$(document).on("pageInit","#" ,function(e, pageId, $page) {});
*/




$.init();